import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { DeptDto } from 'src/app/models/sys/dept.dto';
import { ApiService } from 'src/app/services/api.service';

@Component({
  selector: 'app-dept-detail',
  templateUrl: './dept-detail.component.html',
  styleUrl: './dept-detail.component.less'
})
export class DeptDetailComponent implements OnInit {
  @Input() deptSubject = new BehaviorSubject<DeptDto>(new DeptDto());
  @Output() detailEvent = new EventEmitter<boolean>();

  dept?: DeptDto;

  constructor(private _api: ApiService) {

  }

  ngOnInit(): void {
    this.deptSubject.subscribe((value) => {
      this.dept = value;

      if (this.dept.children != null && this.dept.children.length > 0) {
        this.dept.isLeaf = false;
      } else {
        this.dept.isLeaf = true;
      }
    });
  }

  onClose(event: UIEvent) {
    event.preventDefault();

    this.detailEvent.emit(true);
  }
}
